package cn.felord.r2dbc.repository;

import cn.felord.r2dbc.domain.ClientUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * @author ycd0075
 * @date 2024-01-10 17:18
 */
@Service
public class ClientUserDAO implements BaseDao<ClientUser> {

    @Autowired
    private ReactiveMongoTemplate reactiveMongoTemplate;

    @Override
    public ReactiveMongoTemplate getMongoTemplate() {
        return reactiveMongoTemplate;
    }

    @Override
    public Class getTClass() {
        return ClientUser.class;
    }


    public Mono<ClientUser> queryById(String id) {
        Criteria criteria = Criteria.where("id").is(id);
        Query query = Query.query(criteria);

        return getMongoTemplate().findOne(query, getTClass());
    }
}
